<?php

class IndexsearchController extends Controller {
    public function index(){
        import("Org.Page");
    	$this->assign('title',"康冠智库");
        $search=$_POST['search'];
        if(cookie('km')=="咨询智库"){
            $m=M('Ctgl');
            $ctgl['_string']="(title like '%$search%')OR( content like '%$search%')";
            $count = $m->field(true)->where($ctgl)->count();
            $this->assign('count', $count); 
            $Page = new Page($count,10);
            $show = $Page->show();
            $list = $m->field(true)->order('id')->limit($Page->firstRow.','.$Page->listRows)->where($ctgl)->select();
            $this->assign('list', $list); 
            $this->assign('page',$show);
            $this->display();
        }else if(cookie('km')=="竞价智库"){
            $m=M('Jjzk');
            $jjzk['_string']="(keyname like '%$search%')  OR ( cytitle like '%$search%') OR ( cyms1 like '%$search%') OR ( cyms2 like '%$search%') ";
            $count = $m->field(true)->where($jjzk)->count();
            $this->assign('count', $count); 
            $Page = new Page($count,10);
            $show = $Page->show();
            $list = $m->field(true)->order('id')->limit($Page->firstRow.','.$Page->listRows)->where($jjzk)->select();
            $this->assign('list', $list); 
            $this->assign('page',$show);
            $this->display();
        }
    }
    public function update(){
        $date=date('Y-m-d H:i:s');
        if(cookie('km')=="咨询智库"){
            $m=M('Ctgl');
            $id['id']=$_POST['id'];
            $ctgl['updatename']=cookie('name');
            $ctgl['title']=$_POST['title'];
            $ctgl['content']=$_POST['content'];
            $m->where($id)->save($ctgl);
        }else if(cookie('km')=="竞价智库"){
            $m=M('Jjzk');
            $id['id']=$_POST['id'];
            $jjzk['updatename']=cookie('name');
            $jjzk['keyname']=$_POST['keyname'];
            $jjzk['cytitle']=$_POST['cytitle'];
            $jjzk['cyms1']=$_POST['cyms1'];
            $jjzk['cyms2']=$_POST['cyms2'];
            $jjzk['pchttp1']=$_POST['pchttp1'];
            $jjzk['pchttp2']=$_POST['pchttp2'];
            $jjzk['pchttp3']=$_POST['pchttp3'];
            $jjzk['sjhttp1']=$_POST['sjhttp1'];
            $jjzk['sjhttp2']=$_POST['sjhttp2'];
            $jjzk['sjhttp3']=$_POST['sjhttp3'];
            $m->where($id)->save($jjzk);
        }
    }
}